<?php
/**
 * Created by HBuilder.
 * User: Ason
 * Date: 15-12-29
 * Time: 下午15:51
 */
?>
<div class="modal-dialog modal-lg">
	<div class="modal-content">

		<div class="modal-header bordered-bottom-3 bordered-orange">
			<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
					class="sr-only">Close</span></button>
			<h4 class="modal-title"><span class="glyphicon glyphicon-pencil"></span>编辑考场信息</h4>
		</div>
		<div class="modal-body">
			<!--错误提示 BEGIN-->
				<div id="edit_alert" class="alert text-center" style="display:none;"></div>
			<!--错误提示 END-->
			<form class="form">
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">考试场次ID</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control disabled" name="e_id" id="e_id" value="<?=$exam['id'];?>" disabled>
						</div>
					</div>
				</div>
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">考试班级</label>

					<select name="e_class" id="e_class">
					<?php
					if( empty( $class ) ):
					?>
						<option>请先到【考生管理】添加班级信息！</option>
					<?php
					else:
						foreach( $class as $c ):?>
						<option value="<?=$c['cid'];?>" <?php if( $c[ 'cid' ] == $exam[ 'class' ] ) echo "selected";?>><?=$c[ 'cname' ];?></option>
					<?php
						endforeach;
					endif;
					?>
					</select>
				</div>

				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">开考时间</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="datetime-local" class="form-control" name="e_time" id="e_time" step="1" value="<?=date( 'Y-m-d'.'\T'.'H:i:s', strtotime( $exam['time'] ) );?>">
						</div>
					</div>
				</div>
			</form>

		</div>
		<div class="modal-footer">
			<div class="form-group text-right">
				<button class="btn btn-success" id="edit_exam">确认修改</button>&nbsp;&nbsp;&nbsp;&nbsp;
				<button class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>


	</div>
</div>
<script>
	$("#edit_exam").click(function(){
		$.post(
			"<?=site_url('exam/do_edit_exam')?>",
			{
				id:<?=$exam[ 'id' ];?>,
				class: $( "#e_class" ).val(),
				time: $( "#e_time" ).val(),
			},
			function( json ){
				$( '#edit_alert' ).removeClass( 'alert-danger show').text('');
				data = eval( '(' + json + ')' );
				if( data.status == 'error' ){
					$('#edit_alert' ).addClass('alert-danger show').text( data.error );
				}else{
					$('#edit_alert' ).addClass('alert-success show').text( data.error );
					setTimeout( function(){
						window.location.reload();
					}, 2000);
				}
			}
		)
	});
</script>